package edu.mit.media.fv.components
{
	import flash.display.*;
	import flash.events.MouseEvent;
	import flash.text.*;
	
	public class FVList extends Sprite
	{
		
		private var _cellHeight:int = 28;
		private var _items:Array = new Array();//array of objects
		private var _index:int = 0;
		private var scroll:FVGlassScrollPane;
		
		private var _width:int;
		private var _height:int;
		private var barWidth:int = 25;
		
		public function FVList(x:int, y:int, width:int, height:int){
			super();
			this.scroll = new FVGlassScrollPane(0,0,100,100);
			this.addChild(this.scroll);
			
			this.setBounds(x,y,width, height);
			
		}
		
		public function setBounds(x:int, y:int, width:int, height:int):void{
			this.x = x;
			this.y = y;
			this._width = width;
			this._height = height;
			
			this.graphics.clear();
			this.graphics.beginFill(0xFFFFFF, 0.12);
			this.graphics.lineStyle(1,0xFFFFFF,0.70,true);
			this.graphics.endFill();
			
			this.scroll.setBounds(0,0,width, height);
			this.scroll.background = true;
		}
		
		public function get items():Array{
			return this._items;
		}
		public function setItems(items:Array, action:Function = null):void{
			this._items = items.slice();
			
			var viewport:Sprite = new Sprite();
			for(var i:int = 0; i<items.length; i++){
				var cell:FVTextField = new FVTextField(
					10, 10+this._cellHeight*(i),
					this._width-this.barWidth-10,this._cellHeight, items[i].toString());
				cell.editable = false;
				cell.mouseEnabled = true;
				if(action != null){
					cell.addEventListener(MouseEvent.CLICK, action);
				}
				viewport.addChild(cell);
			}
			this.scroll.viewport = viewport;
			this.scroll.reform();
		}
		private function processMouseClicked(event:MouseEvent):void{
			this.dispatchEvent(new FVChangeEvent(FVChangeEvent.VALUE_CHANGED, -1));
		}
	}
}